package com.ahdy.service.impl;

import com.ahdy.entity.FamilyUser;
import com.ahdy.mapper.FamilyUserMapper;
import com.ahdy.service.FamilyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 子女用户服务实现类
 */
@Service
public class FamilyUserServiceImpl implements FamilyUserService {

    @Autowired
    private FamilyUserMapper familyUserMapper;

    @Override
    @Transactional
    public Integer addFamilyUser(FamilyUser familyUser) {
        familyUserMapper.insert(familyUser);
        return familyUser.getId();
    }

    @Override
    @Transactional
    public int updateFamilyUser(FamilyUser familyUser) {
        return familyUserMapper.update(familyUser);
    }

    @Override
    @Transactional
    public int deleteFamilyUser(Integer id) {
        return familyUserMapper.deleteById(id);
    }

    @Override
    public FamilyUser getFamilyUserById(Integer id) {
        return familyUserMapper.findById(id);
    }

    @Override
    public List<FamilyUser> getAllFamilyUsers() {
        return familyUserMapper.findAll();
    }

    @Override
    public FamilyUser getFamilyUserByPhone(String phone) {
        return familyUserMapper.findByPhone(phone);
    }

    @Override
    public FamilyUser login(String phone, String password) {
        return familyUserMapper.findByPhoneAndPassword(phone, password);
    }

    @Override
    public List<FamilyUser> getFamilyUsersByElderlyId(Integer elderlyId) {
        return familyUserMapper.findFamilyByElderlyId(elderlyId);
    }
}